//package com.lanyun.aicorrectassistant.task;
//
//import cn.hutool.core.collection.CollectionUtil;
//import com.lanyun.aicorrectassistant.basic.entity.StudentAssignments;
//import com.lanyun.aicorrectassistant.basic.service.StudentAssignmentsService;
//import com.lanyun.aicorrectassistant.domain.studentAssignments.StudentAssignmentsDomainService;
//import com.lanyun.aicorrectassistant.enums.AssignmentEnum;
//import com.lanyun.aicorrectassistant.enums.IsDeletedFlagEnum;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.scheduling.annotation.Scheduled;
//import org.springframework.stereotype.Component;
//
//import java.util.List;
//
///**
// * 自动批改作业定时任务
// * 功能：扫描待批改的作业
// */
//@Slf4j
//@Component
//public class AssignmentAutoCancelTask {
//
//    private final StudentAssignmentsDomainService studentAssignmentsDomainService;
//
//    private final StudentAssignmentsService studentAssignmentsService;
//
//    public AssignmentAutoCancelTask(StudentAssignmentsDomainService studentAssignmentsDomainService,
//                                    StudentAssignmentsService studentAssignmentsService) {
//        this.studentAssignmentsDomainService = studentAssignmentsDomainService;
//        this.studentAssignmentsService = studentAssignmentsService;
//    }
//
//    /**
//     * 定时任务入口
//     * <p>
//     * 执行频率：每五分钟触发一次
//     */
//    @Scheduled(cron = "0 */5 * * * ?")
//    public void autoCancelUnpaidOrders() {
//        log.info("[定时任务] 开始扫描待批改作业...");
//        StudentAssignments studentAssignments = new StudentAssignments();
//        studentAssignments.setStatus(AssignmentEnum.PENDING.getCode());
//        studentAssignments.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getVal());
//        List<StudentAssignments> studentAssignmentsList = studentAssignmentsService.queryAllByCondition(studentAssignments);
//        try {
//            if (CollectionUtil.isNotEmpty(studentAssignmentsList)) {
//                for (StudentAssignments assignments : studentAssignmentsList) {
//                    studentAssignmentsDomainService.saveGradingResult(assignments);
//                }
//                log.info("[定时任务] 成功批改作业");
//            }
//        } catch (Exception e) {
//            studentAssignments.setStatus(AssignmentEnum.PENDING.getCode());
//            List<StudentAssignments> errStudentAssignmentsList = studentAssignmentsService.queryAllByCondition(studentAssignments);
//            for (StudentAssignments assignments : errStudentAssignmentsList) {
//                studentAssignmentsDomainService.saveGradingResult(assignments);
//            }
//            log.error("[定时任务] 作业自动批改异常", e);
//        }
//    }
//}